Returns the date or time in a specified format.
Syntax
DateTimeFormat("Format", "Date/Time")
Arguments
| Argument | Description |
|---|---|
| Format | Format to use. |
| Date/Time | Date or time string to format. |
Date and time formatting characters
Formatting depends on the system's regional settings.
| Specifier | Type | Format | Example output |
|---|---|---|---|
| d | Short date | {0:d} | 10/12/2016 |
| D | Long date | {0:D} | December 10, 2016 |
| t | Short time | {0:t} | 10:11 PM |
| T | Long time | {0:T} | 10:11:29 PM |
| f | Full date & time | {0:f} | December 10, 2016 10:11 PM |
| F | Full date & time (long) | {0:F} | December 10, 2016 10:11:29 PM |
| g | Default date & time | {0:g} | 10/12/2016 10:11 PM |
| G | Default date & time (long) | {0:G} | 10/12/2016 10:11:29 PM |
| M | Month day pattern | {0:M} | December 10 |
| r | RFC1123 date string | {0:r} | Tue, 10 Dec 2016 22:11:29 GMT |
| s | Sortable date string | {0:s} | 2016-12-10T22:11:29 |
| u | Universal sortable, local time | {0:u} | 2016-12-10 22:13:50Z |
| Y | Year month pattern | {0:Y} | December, 2016 |
Custom date and time formatting characters
| Specifier | Type | Format | Example output |
|---|---|---|---|
| dd | Day | {0:dd} | 10 |
| ddd | Day name | {0:ddd} | Tue |
| dddd | Full day name | {0:dddd} | Tuesday |
| f, ff, … | Second fractions | {0:fff} | 932 |
| gg, … | Era | {0:gg} | A.D. |
| hh | 2 digit hour | {0:hh} | 10 |
| HH | 2 digit hour, 24hr format | {0:HH} | 22 |
| mm | Minute 00-59 | {0:mm} | 38 |
| MM | Month 01-12 | {0:MM} | 12 |
| MMM | Month abbreviation | {0:MMM} | Dec |
| MMMM | Full month name | {0:MMMM} | December |
| ss | Seconds 00-59 | {0:ss} | 46 |
| tt | AM or PM | {0:tt} | PM |
| yy | Year, 2 digits | {0:yy} | 16 |
| yyyy | Year | {0:yyyy} | 2016 |
| zz | Time zone offset, 2 digits | {0:zz} | -05 |
| zzz | Full time zone offset | {0:zzz} | -05:00 |
| : | Separator | {0:hh:mm:ss} | 10:43:20 |
| / | Separator | {0:dd/MM/yyyy} | 10/12/2016 |
Return value
| Value | Description |
|---|---|
| Value | Date/time in the specified format. |
Example
Dim arrayValues(1)
arrayValues(1) = Now()
var = DateTimeFormat("{0:h:mm:ss tt}", arrayValues(1))
PrintLn(var)